package org.example.springboot.service;

import org.example.springboot.entity.Teach;
import org.example.springboot.entity.Teacher;
import org.example.springboot.entity.TeacherAndCourse;
import org.example.springboot.mapper.TeachMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TeachService {

    @Autowired
    private TeachMapper teachMapper;


    public List<Teach> findByNameAndCourse(String name, String course, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        return teachMapper.findByNameAndCourse(name, course, offset, pageSize);
    }


    public List<Teach> findByName(String name, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        return teachMapper.findByName(name, offset, pageSize);
    }


    public List<Teach> findByCourse(String course, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        return teachMapper.findByCourse(course, offset, pageSize);
    }


    public int countByNameAndCourse(String name, String course) {
        return teachMapper.countByNameAndCourse(name, course);
    }


    public int countByName(String name) {
        return teachMapper.countByName(name);
    }


    public int countByCourse(String course) {
        return teachMapper.countByCourse(course);
    }

    public List<TeacherAndCourse> findByTeacherAndCourse() {
        return teachMapper.findAll();
    }

    public List<Teach> findByAccount(String account) {
        return teachMapper.findByAccount(account);
    }

    @Transactional
    public void deleteTeach(int id) {
        teachMapper.deleteTeach(id);
    }

    @Transactional
    public void insertTeach(Teach teach) {
        teachMapper.insert(teach);
    }
}
